let logger = require('log4js').getLogger("default");
const User = require('../../../models/user/userModel.js')
const { itemNotFound } = require('../../../utils/itemNotFound.js')
const { buildErrObject } = require("../../../utils/buildErrObject");
const findUserByName = async function (user_name = {}) {
    return new Promise((resolve, reject) => {
        User.findOne({ 'user_name': user_name, is_delete: false },
            async (err, item) => {
                try {
                    await itemNotFound(err, item, '用户不存在')
                    if (item.status === '3') return reject(buildErrObject(422, '用户已被封禁'))
                    resolve(item)
                } catch (error) {
                    logger.error(error)
                    reject(error)
                }
            })
    });
};

module.exports = { findUserByName }